package com.itheima.zzyl.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.zzyl.mapper.ReservationMapper;
import com.itheima.zzyl.pojo.PageResult;
import com.itheima.zzyl.pojo.Reservation;
import com.itheima.zzyl.pojo.Result;
import com.itheima.zzyl.service.ReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service("reservationService")
public class ReservationServiceImpl implements ReservationService {
    @Autowired
    private ReservationMapper reservationMapper;

    @Override
    public Result<PageResult<Reservation>> page(Integer pageSize, Integer pageNum, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        List<Reservation> list = reservationMapper.list(status);
        PageInfo<Reservation> pageInfo = new PageInfo<>(list);
        PageResult<Reservation> page = new PageResult<>();
        page.setTotal(pageInfo.getTotal());
        page.setPageSize(pageInfo.getPageSize());
        page.setRecords(pageInfo.getList());
        return Result.success(page);
    }

    @Override
    public void addReservation(Reservation reservation) {
        reservationMapper.insertReservation(reservation);
    }

    @Override
    public void updateReservationStatus(Integer id) {
        reservationMapper.updateStatus(id);
    }
}
